package com.jy.modules.cims.component.sysAssist;

import java.sql.Timestamp;
import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

import com.jy.modules.cims.common.CimsConstant;
import com.jy.modules.cims.common.sysUtils.CollectionsUtils;
import com.jy.modules.cims.common.sysUtils.DateTimeUtils;
import com.jy.modules.cims.common.sysUtils.SearchParamUtil;
import com.jy.modules.cims.common.sysUtils.SimpleBeanUtils;
import com.jy.modules.cims.common.sysUtils.SimpleStringUtils;
import com.jy.modules.cims.component.common.service.TCMmBorrowerAssetService;
import com.jy.modules.cims.component.common.service.TCMmBorrowerAttenService;
import com.jy.modules.cims.component.common.service.TCMmBorrowerBankCardService;
import com.jy.modules.cims.component.common.service.TCMmBorrowerBizEntityService;
import com.jy.modules.cims.component.common.service.TCMmBorrowerCreditInfoService;
import com.jy.modules.cims.component.common.service.TCMmBorrowerInsuranceService;
import com.jy.modules.cims.component.common.service.TCMmBorrowerJobsService;
import com.jy.modules.cims.component.common.service.TCMmBorrowerLoandebtService;
import com.jy.modules.cims.component.common.service.TCMmBorrowerService;
import com.jy.modules.cims.component.common.service.TCMmBorrowerThirdDataService;
import com.jy.modules.cims.data.common.dto.TCMmBorrowerAssetDTO;
import com.jy.modules.cims.data.common.dto.TCMmBorrowerAttenDTO;
import com.jy.modules.cims.data.common.dto.TCMmBorrowerBankCardDTO;
import com.jy.modules.cims.data.common.dto.TCMmBorrowerBizEntityDTO;
import com.jy.modules.cims.data.common.dto.TCMmBorrowerCreditInfoDTO;
import com.jy.modules.cims.data.common.dto.TCMmBorrowerDTO;
import com.jy.modules.cims.data.common.dto.TCMmBorrowerInsuranceDTO;
import com.jy.modules.cims.data.common.dto.TCMmBorrowerJobsDTO;
import com.jy.modules.cims.data.common.dto.TCMmBorrowerLoandebtDTO;
import com.jy.modules.cims.data.common.dto.TCMmBorrowerThirdDataDTO;
import com.jy.modules.cims.data.interact.core.loan.response.BorrowerAssetDTO;
import com.jy.modules.cims.data.interact.core.loan.response.BorrowerAttenDTO;
import com.jy.modules.cims.data.interact.core.loan.response.BorrowerBankCardDTO;
import com.jy.modules.cims.data.interact.core.loan.response.BorrowerBizEntityDTO;
import com.jy.modules.cims.data.interact.core.loan.response.BorrowerCreditInfoDTO;
import com.jy.modules.cims.data.interact.core.loan.response.BorrowerDTO;
import com.jy.modules.cims.data.interact.core.loan.response.BorrowerInsuranceDTO;
import com.jy.modules.cims.data.interact.core.loan.response.BorrowerJobsDTO;
import com.jy.modules.cims.data.interact.core.loan.response.BorrowerLoandebtDTO;
import com.jy.modules.cims.data.interact.core.loan.response.BorrowerThirdDataDTO;

@Service("com.jy.modules.cims.component.sysAssist.BorrowersImpl")
public class BorrowersImpl {
	private static final Logger logger = LoggerFactory.getLogger(BorrowersImpl.class);

	@Autowired
	@Qualifier("com.jy.modules.cims.component.common.service.TCMmBorrowerAttenService")
	private TCMmBorrowerAttenService tcmmBorrowerAttenService;

	@Autowired
	@Qualifier("com.jy.modules.cims.component.common.service.TCMmBorrowerBankCardService")
	private TCMmBorrowerBankCardService tcmmBorrowerBankCardService;

	@Autowired
	@Qualifier("com.jy.modules.cims.component.common.service.TCMmBorrowerBizEntityService")
	private TCMmBorrowerBizEntityService tcmmBorrowerBizEntityService;

	@Autowired
	@Qualifier("com.jy.modules.cims.component.common.service.TCMmBorrowerInsuranceService")
	private TCMmBorrowerInsuranceService tcmmBorrowerInsuranceService;

	@Autowired
	@Qualifier("com.jy.modules.cims.component.common.service.TCMmBorrowerJobsService")
	private TCMmBorrowerJobsService tcmmBorrowerJobsService;

	@Autowired
	@Qualifier("com.jy.modules.cims.component.common.service.TCMmBorrowerService")
	private TCMmBorrowerService tcmmBorrowerService;

	@Autowired
	@Qualifier("com.jy.modules.cims.component.common.service.TCMmBorrowerThirdDataService")
	private TCMmBorrowerThirdDataService tcmmBorrowerThirdDataService;

	@Autowired
	@Qualifier("com.jy.modules.cims.component.common.service.TCMmBorrowerCreditInfoService")
	private TCMmBorrowerCreditInfoService tcmmBorrowerCreditInfoService;

	@Autowired
	@Qualifier("com.jy.modules.cims.component.common.service.TCMmBorrowerLoandebtService")
	private TCMmBorrowerLoandebtService tcmmBorrowerLoandebtService;
	
	@Autowired
	@Qualifier("com.jy.modules.cims.component.common.service.TCMmBorrowerAssetService")
	private TCMmBorrowerAssetService tcmmBorrowerAssetService;

	/**
	 * @description 保存借款人基本信息
	 * @author shengzhoutao
	 * @param borrower
	 * @param contractNo
	 * @param custCode
	 * @throws Exception
	 */
	public void insertTCMmBorrower(final BorrowerDTO borrower, final String contractNo, final String custCode) throws Exception {
		if (null == borrower) {
			return;
		}

		TCMmBorrowerDTO tcmmBorrowerDTO = new TCMmBorrowerDTO();
		tcmmBorrowerDTO.setContractNo(contractNo);
		tcmmBorrowerDTO.setCustCode(custCode);
		List<TCMmBorrowerDTO> tcmmBorrowerList = tcmmBorrowerService.searchTCMmBorrower(SearchParamUtil.getSearchParam(tcmmBorrowerDTO));
		if (CollectionsUtils.isEmpty(tcmmBorrowerList)) {
			tcmmBorrowerDTO = new TCMmBorrowerDTO();
			SimpleBeanUtils.copyBean2Bean(tcmmBorrowerDTO, borrower);
			if(SimpleStringUtils.hasText(borrower.getApprDate())){
				tcmmBorrowerDTO.setApprDate(DateTimeUtils.parse(borrower.getApprDate(), DateTimeUtils.DEFAULT_DATE_FORMAT_2));
			}
			if(SimpleStringUtils.hasText(borrower.getSignDate())){
				tcmmBorrowerDTO.setSignDate(DateTimeUtils.parse(borrower.getSignDate(), DateTimeUtils.DEFAULT_DATE_FORMAT_2));
			}
			if(SimpleStringUtils.hasText(borrower.getIdPeriod())){
				tcmmBorrowerDTO.setIdPeriod(DateTimeUtils.parse(borrower.getIdPeriod(), DateTimeUtils.DEFAULT_DATE_FORMAT_2));
			}
			if(SimpleStringUtils.hasText(borrower.getAffirmDateTime())){
				tcmmBorrowerDTO.setAffirmDateTime(DateTimeUtils.parse(borrower.getAffirmDateTime(), DateTimeUtils.DEFAULT_DATE_TIME_FORMAT));
			}
			tcmmBorrowerDTO.setContractNo(contractNo);
			tcmmBorrowerDTO.setCustCode(custCode);
			tcmmBorrowerDTO.setHDegree(borrower.gethDegree());
			tcmmBorrowerDTO.setCreateTime(new Timestamp(System.currentTimeMillis()));
			tcmmBorrowerDTO.setModifyTime(new Timestamp(System.currentTimeMillis()));
			tcmmBorrowerDTO.setValidateState(CimsConstant.DATE_STATUS_VALID);
			tcmmBorrowerDTO.setHometownApplocation(borrower.getHometownAppLocation());
			long id = tcmmBorrowerService.insertTCMmBorrower(tcmmBorrowerDTO);
			logger.info("保存借款人基本信息生成的主键id:" + id);
		}
		tcmmBorrowerDTO = null;
	}

	/**
	 * @description 保存借款人银行卡信息
	 * @author shengzhoutao
	 * @param bankCardList
	 * @param contractNo
	 * @param custCode
	 * @throws Exception
	 */
	public void insertTCMmBorrowerBankCard(final List<BorrowerBankCardDTO> bankCardList, final String contractNo, final String custCode)
			throws Exception {
		if (CollectionsUtils.isEmpty(bankCardList)) {
			return;
		}

		TCMmBorrowerBankCardDTO tcmmBorrowerBankCardDTO = null;
		TCMmBorrowerBankCardDTO searchBorrowerBankCardDTO = null;
		for (BorrowerBankCardDTO bankCard : bankCardList) {
			searchBorrowerBankCardDTO = new TCMmBorrowerBankCardDTO();
			searchBorrowerBankCardDTO.setContractNo(contractNo);
			searchBorrowerBankCardDTO.setCustCode(custCode);
			searchBorrowerBankCardDTO.setBankCardAccount(bankCard.getBankCardAccount());
			List<TCMmBorrowerBankCardDTO> list = tcmmBorrowerBankCardService.searchTCMmBorrowerBankCard(SearchParamUtil.getSearchParam(searchBorrowerBankCardDTO));
			//验证重复
			if (CollectionsUtils.isEmpty(list)) {
				tcmmBorrowerBankCardDTO = new TCMmBorrowerBankCardDTO();
				SimpleBeanUtils.copyBean2Bean(tcmmBorrowerBankCardDTO, bankCard);
				tcmmBorrowerBankCardDTO.setContractNo(contractNo);
				tcmmBorrowerBankCardDTO.setCustCode(custCode);
				tcmmBorrowerBankCardDTO.setCreateTime(new Timestamp(System.currentTimeMillis()));
				tcmmBorrowerBankCardDTO.setModifyTime(new Timestamp(System.currentTimeMillis()));
				tcmmBorrowerBankCardDTO.setValidateState(CimsConstant.DATE_STATUS_VALID);
				long id = tcmmBorrowerBankCardService.insertTCMmBorrowerBankCard(tcmmBorrowerBankCardDTO);
				logger.info("保存借款人银行卡信息生成的主键id:" + id);
			}
		}
		tcmmBorrowerBankCardDTO = null;
	}

	/**
	 * @description 保存借款人房贷信息
	 * @author shengzhoutao
	 * @param creditInfoList
	 * @param contractNo
	 * @param custCode
	 * @throws Exception
	 */
	public void insertTCMmBorrowerCreditInfo(final List<BorrowerCreditInfoDTO> creditInfoList, final String contractNo, final String custCode)
			throws Exception {
		if (CollectionsUtils.isEmpty(creditInfoList)) {
			return;
		}

		TCMmBorrowerCreditInfoDTO tcmmBorrowerCreditInfoDTO = null;
		TCMmBorrowerCreditInfoDTO searchBorrowerCreditInfoDTO = new TCMmBorrowerCreditInfoDTO();
		searchBorrowerCreditInfoDTO.setContractNo(contractNo);
		searchBorrowerCreditInfoDTO.setCustCode(custCode);
		List<TCMmBorrowerCreditInfoDTO> list = tcmmBorrowerCreditInfoService.searchTCMmBorrowerCreditInfo(SearchParamUtil.getSearchParam(searchBorrowerCreditInfoDTO));
		if (CollectionsUtils.isEmpty(list)) {
			for (BorrowerCreditInfoDTO creditInfo : creditInfoList) {
				tcmmBorrowerCreditInfoDTO = new TCMmBorrowerCreditInfoDTO();
				SimpleBeanUtils.copyBean2Bean(tcmmBorrowerCreditInfoDTO, creditInfo);
				tcmmBorrowerCreditInfoDTO.setContractNo(contractNo);
				tcmmBorrowerCreditInfoDTO.setCustCode(custCode);
				tcmmBorrowerCreditInfoDTO.setLoanOvdHigh(creditInfo.getLoanOVDHigh());
				tcmmBorrowerCreditInfoDTO.setCreateTime(new Timestamp(System.currentTimeMillis()));
				tcmmBorrowerCreditInfoDTO.setModifyTime(new Timestamp(System.currentTimeMillis()));
				tcmmBorrowerCreditInfoDTO.setValidateState(CimsConstant.DATE_STATUS_VALID);
				long id = tcmmBorrowerCreditInfoService.insertTCMmBorrowerCreditInfo(tcmmBorrowerCreditInfoDTO);
				logger.info("保存借款人房贷信息生成的主键id:" + id);
			}
		}
		tcmmBorrowerCreditInfoDTO = null;
	}

	/**
	 * @description 保存借款人征信信息
	 * @author shengzhoutao
	 * @param loandebtList
	 * @param contractNo
	 * @param custCode
	 * @throws Exception
	 */
	public void insertTCMmBorrowerLoandebt(final List<BorrowerLoandebtDTO> loandebtList, final String contractNo, final String custCode)
			throws Exception {
		if (CollectionsUtils.isEmpty(loandebtList)) {
			return;
		}

		TCMmBorrowerLoandebtDTO tcmmBorrowerLoandebtDTO = null;
		TCMmBorrowerLoandebtDTO searchBorrowerLoandebtDTO = new TCMmBorrowerLoandebtDTO();
		searchBorrowerLoandebtDTO.setContractNo(contractNo);
		searchBorrowerLoandebtDTO.setCustCode(custCode);
		List<TCMmBorrowerLoandebtDTO> list = tcmmBorrowerLoandebtService.searchTCMmBorrowerLoandebt(SearchParamUtil.getSearchParam(searchBorrowerLoandebtDTO));
		//验证是否重复
		if (CollectionsUtils.isEmpty(list)) {
			for (BorrowerLoandebtDTO loandebt : loandebtList) {
				tcmmBorrowerLoandebtDTO = new TCMmBorrowerLoandebtDTO();
				SimpleBeanUtils.copyBean2Bean(tcmmBorrowerLoandebtDTO, loandebt);
				tcmmBorrowerLoandebtDTO.setContractNo(contractNo);
				tcmmBorrowerLoandebtDTO.setCustCode(custCode);
				tcmmBorrowerLoandebtDTO.setCreateTime(new Timestamp(System.currentTimeMillis()));
				tcmmBorrowerLoandebtDTO.setModifyTime(new Timestamp(System.currentTimeMillis()));
				tcmmBorrowerLoandebtDTO.setValidateState(CimsConstant.DATE_STATUS_VALID);
				long id = tcmmBorrowerLoandebtService.insertTCMmBorrowerLoandebt(tcmmBorrowerLoandebtDTO);
				logger.info("保存借款人征信信息生成的主键id:" + id);
			}
		}
		tcmmBorrowerLoandebtDTO = null;
	}

	/**
	 * @description 保存借款人经营实体明细
	 * @author shengzhoutao
	 * @param entityList
	 * @param contractNo
	 * @param custCode
	 * @throws Exception
	 */
	public void insertTCMmBorrowerBizEntity(final List<BorrowerBizEntityDTO> entityList, final String contractNo, final String custCode)
			throws Exception {
		if (CollectionsUtils.isEmpty(entityList)) {
			return;
		}

		TCMmBorrowerBizEntityDTO tcmmBorrowerBizEntityDTO = null;
		TCMmBorrowerBizEntityDTO searchBorrowerBizEntityDTO  = new TCMmBorrowerBizEntityDTO();
		searchBorrowerBizEntityDTO.setContractNo(contractNo);
		searchBorrowerBizEntityDTO.setCustCode(custCode);
		List<TCMmBorrowerBizEntityDTO> list = tcmmBorrowerBizEntityService.searchTCMmBorrowerBizEntity(SearchParamUtil.getSearchParam(searchBorrowerBizEntityDTO));
		//检验是否为空
		if (CollectionsUtils.isEmpty(list)) {
			for (BorrowerBizEntityDTO entity : entityList) {
				tcmmBorrowerBizEntityDTO = new TCMmBorrowerBizEntityDTO();
				SimpleBeanUtils.copyBean2Bean(tcmmBorrowerBizEntityDTO, entity);
				tcmmBorrowerBizEntityDTO.setContractNo(contractNo);
				tcmmBorrowerBizEntityDTO.setCustCode(custCode);
				tcmmBorrowerBizEntityDTO.setJAddr(entity.getjAddr());
				tcmmBorrowerBizEntityDTO.setCreateTime(new Timestamp(System.currentTimeMillis()));
				tcmmBorrowerBizEntityDTO.setModifyTime(new Timestamp(System.currentTimeMillis()));
				tcmmBorrowerBizEntityDTO.setValidateState(CimsConstant.DATE_STATUS_VALID);
				long id = tcmmBorrowerBizEntityService.insertTCMmBorrowerBizEntity(tcmmBorrowerBizEntityDTO);
				logger.info("保存借款人经营实体明细生成的主键id:" + id);
			}
		}
		tcmmBorrowerBizEntityDTO = null;
	}

	/**
	 * @description 保存借款人投保信息
	 * @author shengzhoutao
	 * @param insuranceList
	 * @param contractNo
	 * @param custCode
	 * @throws Exception
	 */
	public void insertTCMmBorrowerInsurance(final List<BorrowerInsuranceDTO> insuranceList, final String contractNo, final String custCode)
			throws Exception {
		if (CollectionsUtils.isEmpty(insuranceList)) {
			return;
		}

		TCMmBorrowerInsuranceDTO tcmmBorrowerInsuranceDTO = null;
		TCMmBorrowerInsuranceDTO searchBorrowerInsuranceDTO  = new TCMmBorrowerInsuranceDTO();
		searchBorrowerInsuranceDTO.setContractNo(contractNo);
		searchBorrowerInsuranceDTO.setCustCode(custCode);
		List<TCMmBorrowerInsuranceDTO> list = tcmmBorrowerInsuranceService.searchTCMmBorrowerInsurance(SearchParamUtil.getSearchParam(searchBorrowerInsuranceDTO));
		if (CollectionsUtils.isEmpty(list)) {
			for (BorrowerInsuranceDTO insurance : insuranceList) {
				//检验是否为空
				tcmmBorrowerInsuranceDTO = new TCMmBorrowerInsuranceDTO();
				SimpleBeanUtils.copyBean2Bean(tcmmBorrowerInsuranceDTO, insurance);
				tcmmBorrowerInsuranceDTO.setContractNo(contractNo);
				tcmmBorrowerInsuranceDTO.setCustCode(custCode);
				tcmmBorrowerInsuranceDTO.setCreateTime(new Timestamp(System.currentTimeMillis()));
				tcmmBorrowerInsuranceDTO.setModifyTime(new Timestamp(System.currentTimeMillis()));
				tcmmBorrowerInsuranceDTO.setValidateState(CimsConstant.DATE_STATUS_VALID);
				long id = tcmmBorrowerInsuranceService.insertTCMmBorrowerInsurance(tcmmBorrowerInsuranceDTO);
				logger.info("保存借款人投保信息生成的主键id:" + id);
				
			}
		}
		tcmmBorrowerInsuranceDTO = null;
	}

	/**
	 * @description 保存借款人工作信息
	 * @author shengzhoutao
	 * @param jobs
	 * @param contractNo
	 * @param custCode
	 * @throws Exception
	 */
	public void insertTCMmBorrowerJobs(final BorrowerJobsDTO jobs, final String contractNo, final String custCode) throws Exception {
		if (null == jobs) {
			return;
		}

		TCMmBorrowerJobsDTO tcmmBorrowerJobsDTO = new TCMmBorrowerJobsDTO();
		tcmmBorrowerJobsDTO.setContractNo(contractNo);
		tcmmBorrowerJobsDTO.setCustCode(custCode);
		List<TCMmBorrowerJobsDTO> tcmmBorrowerJobsList = tcmmBorrowerJobsService.searchTCMmBorrowerJobs(SearchParamUtil
				.getSearchParam(tcmmBorrowerJobsDTO));
		if (CollectionsUtils.isEmpty(tcmmBorrowerJobsList)) {
			SimpleBeanUtils.copyBean2Bean(tcmmBorrowerJobsDTO, jobs);
			tcmmBorrowerJobsDTO.setContractNo(contractNo);
			tcmmBorrowerJobsDTO.setCustCode(custCode);
			tcmmBorrowerJobsDTO.setJMonincome(jobs.getjMonIncome());
			tcmmBorrowerJobsDTO.setJAddr(jobs.getjAddr());
			tcmmBorrowerJobsDTO.setJName(jobs.getjName());
			tcmmBorrowerJobsDTO.setJType(jobs.getjType());
			tcmmBorrowerJobsDTO.setJPhone(jobs.getjPhone());
			tcmmBorrowerJobsDTO.setJPosition(jobs.getjPosition());
			tcmmBorrowerJobsDTO.setCreateTime(new Timestamp(System.currentTimeMillis()));
			tcmmBorrowerJobsDTO.setModifyTime(new Timestamp(System.currentTimeMillis()));
			tcmmBorrowerJobsDTO.setValidateState(CimsConstant.DATE_STATUS_VALID);
			if (SimpleStringUtils.hasText(jobs.getjEnterT())) {
				try {
					tcmmBorrowerJobsDTO.setJEntert(DateTimeUtils.parse(jobs.getjEnterT(), DateTimeUtils.DEFAULT_DATE_TIME_FORMAT));
				} catch (Exception e) {
					logger.error("", e);
				}
			}

			long id = tcmmBorrowerJobsService.insertTCMmBorrowerJobs(tcmmBorrowerJobsDTO);
			logger.info("保存借款人工作信息生成的主键id:" + id);
		}
		tcmmBorrowerJobsDTO = null;
	}

	/**
	 * @description 保存借款人第三方测试数据
	 * @author shengzhoutao
	 * @param thirdData
	 * @param contractNo
	 * @param custCode
	 * @throws Exception
	 */
	public void insertTCMmBorrowerThirdData(final BorrowerThirdDataDTO thirdData, final String contractNo, final String custCode) throws Exception {
		if (null == thirdData) {
			return;
		}
		TCMmBorrowerThirdDataDTO searchBorrowerThirdDataDTO = new TCMmBorrowerThirdDataDTO();
		searchBorrowerThirdDataDTO.setContractNo(contractNo);
		searchBorrowerThirdDataDTO.setCustCode(custCode);
		List<TCMmBorrowerThirdDataDTO> list = tcmmBorrowerThirdDataService.searchTCMmBorrowerThirdData(SearchParamUtil.getSearchParam(searchBorrowerThirdDataDTO));
		//判断是否为空
		TCMmBorrowerThirdDataDTO tcmmBorrowerThirdDataDTO = null;
		if (CollectionsUtils.isEmpty(list)) {
			tcmmBorrowerThirdDataDTO = new TCMmBorrowerThirdDataDTO();
			SimpleBeanUtils.copyBean2Bean(tcmmBorrowerThirdDataDTO, thirdData);
			tcmmBorrowerThirdDataDTO.setContractNo(contractNo);
			tcmmBorrowerThirdDataDTO.setCustCode(custCode);
			tcmmBorrowerThirdDataDTO.setCreateTime(new Timestamp(System.currentTimeMillis()));
			tcmmBorrowerThirdDataDTO.setModifyTime(new Timestamp(System.currentTimeMillis()));
			tcmmBorrowerThirdDataDTO.setValidateState(CimsConstant.DATE_STATUS_VALID);
			long id = tcmmBorrowerThirdDataService.insertTCMmBorrowerThirdData(tcmmBorrowerThirdDataDTO);
			logger.info("保存借款人第三方测试数据生成的主键id:" + id);
		}
		tcmmBorrowerThirdDataDTO = null;
	}

	/**
	 * @description 保存借款人联系人信息
	 * @author shengzhoutao
	 * @param contactInfoList
	 * @param contractNo
	 * @param custCode
	 * @throws Exception
	 */
	public void insertTCMmBorrowerAtten(final List<BorrowerAttenDTO> contactInfoList, final String contractNo, final String custCode)
			throws Exception {
		if (CollectionsUtils.isEmpty(contactInfoList)) {
			return;
		}
		TCMmBorrowerAttenDTO tcmmBorrowerAttenDTO = null;
		TCMmBorrowerAttenDTO searchBorrowerAttenDTO = new TCMmBorrowerAttenDTO();
		searchBorrowerAttenDTO.setContractNo(contractNo);
		searchBorrowerAttenDTO.setCustCode(custCode);
		List<TCMmBorrowerAttenDTO> list = tcmmBorrowerAttenService.searchTCMmBorrowerAtten(SearchParamUtil.getSearchParam(searchBorrowerAttenDTO));
		if (CollectionsUtils.isEmpty(list)) {
			for (BorrowerAttenDTO contactInfo : contactInfoList) {
				tcmmBorrowerAttenDTO = new TCMmBorrowerAttenDTO();
				SimpleBeanUtils.copyBean2Bean(tcmmBorrowerAttenDTO, contactInfo);
				tcmmBorrowerAttenDTO.setContractNo(contractNo);
				tcmmBorrowerAttenDTO.setCustCode(custCode);
				tcmmBorrowerAttenDTO.setConPhoneAreacode(contactInfo.getConPhoneAreaCode());
				tcmmBorrowerAttenDTO.setCreateTime(new Timestamp(System.currentTimeMillis()));
				tcmmBorrowerAttenDTO.setModifyTime(new Timestamp(System.currentTimeMillis()));
				tcmmBorrowerAttenDTO.setValidateState(CimsConstant.DATE_STATUS_VALID);
				long id = tcmmBorrowerAttenService.insertTCMmBorrowerAtten(tcmmBorrowerAttenDTO);
				logger.info("保存借款人联系人信息生成的主键id:" + id);
			}
		}
		tcmmBorrowerAttenDTO = null;
	}
	/**
	 * 保存借款人房产信息
	 * @author zhangmi
	 * @date  2016年11月29日
	 * @param assetList
	 * @param contractNo
	 * @param custCode
	 * @throws Exception
	 */
	public void insertTCMmBorrowerAsset(final List<BorrowerAssetDTO> assetList, final String contractNo, final String custCode)
			throws Exception {
		if (CollectionsUtils.isEmpty(assetList)) {
			return;
		}
		TCMmBorrowerAssetDTO tcmmBorrowerAssetDTO = null;
		TCMmBorrowerAssetDTO searchBorrowerAssetDTO = new TCMmBorrowerAssetDTO();
		searchBorrowerAssetDTO.setContractNo(contractNo);
		searchBorrowerAssetDTO.setCustCode(custCode);
		List<TCMmBorrowerAssetDTO> list = tcmmBorrowerAssetService.searchTCMmBorrowerAsset(SearchParamUtil.getSearchParam(searchBorrowerAssetDTO));
		if (CollectionsUtils.isEmpty(list)) {
			for (BorrowerAssetDTO borrowerAsset : assetList) {
				tcmmBorrowerAssetDTO = new TCMmBorrowerAssetDTO();
				SimpleBeanUtils.copyBean2Bean(tcmmBorrowerAssetDTO, borrowerAsset);
				tcmmBorrowerAssetDTO.setContractNo(contractNo);
				tcmmBorrowerAssetDTO.setCustCode(custCode);
				//tcmmBorrowerAssetDTO.setConPhoneAreacode(contactInfo.getConPhoneAreaCode());
				if(SimpleStringUtils.hasText(borrowerAsset.getBuyTime())){
					tcmmBorrowerAssetDTO.setBuyTime(DateTimeUtils.parse(borrowerAsset.getBuyTime(), DateTimeUtils.DEFAULT_DATE_FORMAT_2));
				}
				tcmmBorrowerAssetDTO.setCreateTime(new Timestamp(System.currentTimeMillis()));
				tcmmBorrowerAssetDTO.setModifyTime(new Timestamp(System.currentTimeMillis()));
				tcmmBorrowerAssetDTO.setValidateState(CimsConstant.DATE_STATUS_VALID);
				long id = tcmmBorrowerAssetService.insertTCMmBorrowerAsset(tcmmBorrowerAssetDTO);
				logger.info("保存借款人房产信息生成的主键id:" + id);
			}
		}
		tcmmBorrowerAssetDTO = null;
	}
	
}
